//
//  EAMealSetViewController.swift
//  WhatToEat
//
//  Created by 方力 on 15/12/3.
//  Copyright © 2015年 Mac. All rights reserved.
//
import Foundation
import UIKit


class EAMealSetViewController: UIViewController,UITableViewDataSource,UITableViewDelegate{

    var tableView:UITableView?
    
    var dataSouth:NSMutableArray?
    var mealtype: String?
    var aty_level:String?
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        
        
        
        self.view.backgroundColor=(UIColor .whiteColor());
        self.navigationItem.title="餐量设定";
        

        
        
        self.navigationItem.rightBarButtonItem=UIBarButtonItem(title: "下一步", style: UIBarButtonItemStyle.Plain, target: self, action: "nextSet");
        self.tableView=UITableView();

        self.tableView?.frame=self.view.bounds;
        
        self.tableView?.delegate=self;
        self.tableView?.dataSource=self;
        
        self.view .addSubview(self.tableView!);
        self.tableView? .registerNib(UINib(nibName: "EARecommendMealCell", bundle:nil), forCellReuseIdentifier: "EARecommendMealCell");

    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        
        return (dataSouth?.count)!;
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
     
        
    
        let cell=tableView.dequeueReusableCellWithIdentifier("EARecommendMealCell", forIndexPath: indexPath)as?EARecommendMealCell;
        
        let d=dataSouth!.objectAtIndex(indexPath.row) as? NSDictionary;
        

        cell?.nameLabel.text=d!["name"]as? String
        ;
        
        cell?.headImageURL=d!["img"]as?String;
        
//        cell?.numberLabel.text="X1";
        

        cell?.addBtn .addTarget(self, action: "addAction:", forControlEvents: UIControlEvents.TouchUpInside);
        
        cell?.foodsBtn .addTarget(self, action: "plusAction:", forControlEvents: UIControlEvents.TouchUpInside);
        
        let str:String=d!["mun"] as! String;
        
        
        




        
        return cell!;

    }
    

    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        
        return 80;
   
    }

    func nextSet(){

        print("下一步");
    
        
        print(dataSouth);
        
        
  let ss=UIApplication .sharedApplication().delegate as!(AppDelegate)


        ss.sendMealWithMeals(dataSouth, andMealType: mealtype, andAty_level: aty_level);
        

        
    }
    

    func addAction(cell:EARecommendMealCell)
    {
    
    
    
    }
    
    func plusAction(cell:EARecommendMealCell)
    {
    
    
    
    }
    
}
